;(function() {
	'use strict';
	angular.module('services.sysServiceData.uPayCommissionRate')
		.factory('uPayCommissionRateService', uPayCommissionRateService);

	function uPayCommissionRateService(Restangular) {
		return {
			getPageBind: function() {
				var year = new Date().getFullYear();
				return {
					timeType: '5',
					startTime: year,
					endTime: year
				};
			},
			queryScore: function(params, callback) {
				Restangular.all('sas/sysServiceData/uPay/UpayCSAScore').post(params).then(callback);
			},
			queryScoreDet: function(params, callback) {
				Restangular.all('sas/sysServiceData/uPay/UpayCSAScoreDet').post(params).then(callback);
			},
			queryScoreDetTable: function(params, callback) {
				Restangular.all('sas/sysServiceData/uPay/UpayCSAScoreTable').post(params).then(callback);
			},
			getEchartsData: function(items, title) {
				var temp = {
					echartsX: [],
					total: [],
					validTotal: [],
					score: []
				};
				angular.forEach(items, function(item) {
					if (temp.echartsX.indexOf(item.time) === -1) {
						temp.echartsX.push(item.time);
						temp.score.push(item.score);
						temp.validTotal.push(item.validTotal);
						temp.total.push(item.total);
					}
				});
				var option = {
					title: {
						text: title,
						x: 'center'
					},
					animation: false,
					dataZoom: {
						show: true,
						realtime: true
					},
					legend: {
						orient: 'vertical',
				        data:['总投诉数','有效投诉'],
				        x: 'right',
				        y: 'center'
				    },
					grid: {
						x2: 100
					},
					tooltip: {
						show: true
					},
					xAxis: [{
						type: 'category',
						data: temp.echartsX
					}],
					yAxis: [{
						type: 'value',
						name: '总投诉数'
					}, {
						type: 'value',
						name: '有效投诉'
					}],
					series: [{
						name: '总投诉数',
						type: 'bar',
						data: temp.total
					}, {
						name: '有效投诉',
						type: 'line',
						data: temp.validTotal
					}]
				};
				return option;
			}
		};
	}
})();